import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.Arrays;


class Student {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }


    public void test() {

    }
}


public class Test {
    public static void main18(String[] args) {
        final int array[] = {1,2,3,4,5};
        array[0] = 100;
        System.out.println(Arrays.toString(array));
        //array = new int[]{4,5,6}; // 编译报错：Error:(19, 9) java: 无法为最终变量array分配值
    }


    public static void main17(String[] args) {
        String str = "  fasafasafdsa  fasafsaf  ";
        System.out.println(str);
        //去掉字符串的左右两边的空格，中间的空格无法去掉
        System.out.println(str.trim());
    }


    public static void main16(String[] args) {

        String str = "ababc";
        String ret = str.substring(2);
        System.out.println(ret);

        String ret2 = str.substring(1,3);//截取范围左闭又开[1,3)
        System.out.println(ret2);

    }

    public static void main15(String[] args) {
        String str = "192\\168\\1\\1";
        String[] s1 = str.split("\\\\");
        for (String s : s1) {
            System.out.println(s);
        }

        System.out.println("=====================");
        String str2 = "name=zhangsan&age=15";
        String[] s2 = str2.split("=|&");
        for (String s : s2) {
            System.out.println(s);
        }

        System.out.println("=====================");
        String str3 = "name=zhangsan&age=15";
        String[] s3 = str3.split("=");
        for (int i = 0; i < s3.length; i++) {
            //System.out.println(s3[i]);
            String[] s4 = s3[i].split("&");
            for (int j = 0; j < s4.length; j++) {
                System.out.println(s4[j]);
            }
        }




        /*String str = "192.168.1.1" ;
        String[] result = str.split("\\.");
        for(String s: result) {
            System.out.println(s);
        }*/
    }


    public static void main14(String[] args) {

        String str = "hello abc world";
        String[] ret = str.split(" ");//以空格分,全部拆分
        for (int i = 0; i < ret.length; i++) {
            System.out.println(ret[i]);
        }
        System.out.println("=========================");

        String str2 = "hello abc world";
        String[] ret2 = str2.split(" ", 2);//以空格分，拆分为limit组
        for (int i = 0; i < ret2.length; i++) {
            System.out.println(ret2[i]);
        }
    }


    public static void main13(String[] args) {
        String str = "ababcabcdabcde";
        String ret = str.replace("ab", "999");
        System.out.println(ret);

        ret = str.replace('a', '8');
        System.out.println(ret);

        ret = str.replaceAll("ab", "123");
        System.out.println(ret);

        ret = str.replaceFirst("ab", "ppp");
        System.out.println(ret);
    }


    public static void main12(String[] args) {
        String s = String.format("%d-%d-%d", 2019, 9, 14);
        System.out.println(s);
    }


    public static void main11(String[] args) {
        String s1 = "hello";
        // 字符串转数组
        char[] array1 = s1.toCharArray();
        System.out.println(Arrays.toString(array1));
        // 数组转字符串
        char[] array2 = {'a', 'b', 'c'};
        String str2 = new String(array2);
        System.out.println(str2);
    }


    public static void main(String[] args) {
        String s1 = "hello中文";
        String s2 = "HELLO中文";
        // 小写转大写
        //转变为大写或者小写，不是在原来的基础上转变的，是转变成大写或者小写后是一个新的对象。
        String ret1 = s1.toUpperCase();
        System.out.println(ret1);
        System.out.println(s1);
        System.out.println("=======================");
        // 大写转小写
        String ret2 = s2.toLowerCase();
        System.out.println(ret2);
        System.out.println(s2);
    }

    public static void main9(String[] args) {
        // 数字转字符串
        String s1 = String.valueOf(1234);
        String s2 = String.valueOf(12.34);
        String s3 = String.valueOf(true);
        String s4 = String.valueOf(new Student("Hanmeimei", 18));
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);
        System.out.println("=================================");
        // 字符串转数字
        // 注意：Integer、Double等是Java中的包装类型，这个后面会讲到
        int data1 = Integer.parseInt("1234");
        double data2 = Double.parseDouble("12.34");
        System.out.println(data1);
        System.out.println(data2);
    }


    public static void main8(String[] args) {
        String s1 = new String("ababcabcd");
        int index = s1.lastIndexOf("abc", 4);
        System.out.println(index);


        /*int index = s1.indexOf("abc",3);
        System.out.println(index);*/


        //String s1 = new String("hello");
        //从头到尾 查某个字符 第一次出现的下标
        /*int index = s1.indexOf('l',3);
        System.out.println(index);*/


        /*char ch = s1.charAt(1);
        System.out.println(ch);*/
        /*for (int i = 0; i < s1.length(); i++) {
            char ch = s1.charAt(i);
            System.out.println(ch);
        }*/

    }


    public static void main7(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("ac");
        String s3 = new String("ABc");
        String s4 = new String("abcdef");
        System.out.println(s1.compareToIgnoreCase(s2)); // 不同输出字符差值-1
        System.out.println(s1.compareToIgnoreCase(s3)); // 相同输出 0
        System.out.println(s1.compareToIgnoreCase(s4)); // 前k个字符完全相同，输出长度差值 -3
    }


    public static void main6(String[] args) {
        String s1 = new String("abc");
        String s2 = new String("ac");
        String s3 = new String("abc");
        String s4 = new String("abcdef");
        System.out.println(s1.compareTo(s2)); // 不同输出字符差值-1
        System.out.println(s1.compareTo(s3)); // 相同输出 0
        System.out.println(s1.compareTo(s4)); // 前k个字符完全相同，输出长度差值 -3
        System.out.println(s2.compareTo(s1));
        System.out.println(s3.compareTo(s2));
        System.out.println(s2.compareTo(s4));

    }


    public static void main5(String[] args) {
        String str1 = new String("hello");
        String str3 = new String("hello");
        String str2 = new String("world");

        System.out.println(str1 == str2);
        System.out.println(str1.equals(str2));//false
        System.out.println(str1.equals(str3));//false

        /*String str3 = new String("my");
        String str4 = str3;
        System.out.println(str3 == str4);*/
    }


    public static void main4(String[] args) {
        String str1 = "";
        String str2 = null;
        System.out.println(str1.isEmpty());//如果字符串长度为0，返回true，否则返回false
        //System.out.println(str2.isEmpty());//空指针异常

        System.out.println(str1);//空，什么都没有
        System.out.println(str2);//null

        System.out.println("".length());//0
        System.out.println(str1.length());//0
        System.out.println(str2.length());//空指针异常


        // 打印"hello"字符串(String对象)的长度
        /*System.out.println("hello".length());//5
        System.out.println("".length());//0*/
    }


    public static void main3(String[] args) {
        // s1和s2引用的是不同对象 s1和s3引用的是同一对象
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = s1;
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);

        System.out.println(s1.length());
        System.out.println(s2.length());
        System.out.println(s3.length());
    }


    public static void main2(String[] args) {
        char[] array = {'h', 'e', 'l', 'l', 'o'};
        String str4 = new String(array, 0, 2);
        System.out.println(str4);
    }

    public static void main1(String[] args) {
        //使用字符串构造， "hello" —》 字符串常量
        String str1 = "hello";
        System.out.println(str1);

        //直接new String对象
        String str2 = new String();
        System.out.println(str2);
        String str3 = new String("hello");
        System.out.println(str3);

        //使用字符数组进行构造
        char[] array = {'h', 'e', 'l', 'l', 'o'};
        String str4 = new String(array);
        System.out.println(str4);
    }
}
